<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Team Bonus Summary</title>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="/js/jquery.leanModal.min.js"></script>
<link type="text/css" href="/css/start/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />	
<script language="javascript"> 
function toggle(str) {
	var ele = document.getElementById(str);

	if(ele.style.display == "") {
		ele.style.display = "none";
  	}
	else {
		ele.style.display = "";
	}
}

function tickAll(source){
	var currentId = $(source).attr('id');
	var id = currentId.split("_");
	var checkId = "check_release_"+id[1];
	var checkId2 = "check_delay_"+id[1];
	var checkId3 = "pay_date_check_" +id[1];
	if(id[0] == 'tickAll1'){
		
		if(source.checked){
			$('.'+ checkId).prop('checked',true);
		}else{
			$('.'+ checkId).prop('checked',false);
		}
	}else if(id[0] == 'tickAll2'){
		if(source.checked){
			$('.'+ checkId2).prop('checked',true);
		}else{
			$('.'+ checkId2).prop('checked',false);
		}
	}else{
		if(source.checked){
			$('.'+ checkId3).prop('checked',true);
		}else{
			$('.'+ checkId3).prop('checked',false);
		}
	}	

}


$(function() {
	$( ".date" ).datepicker({ dateFormat: "yy-mm-dd",firstDay: 1 });
	$( ".pick_date" ).datepicker({ dateFormat: "yy-mm-dd",firstDay: 1 });
});	

function changeDate(source){
		var changeValue = $(source).attr('value');
		$("input[id^='date_release']").attr('value',changeValue);
}

function changeCycle(source){
	var changeValue = $(source).attr('value');
	$(".choose_cycle option[value = " + changeValue + " ]").attr('selected',true);
}
</script>

</head>
<body style="font-family:Arial, Helvetica, sans-serif; line-height:20px;">
<form method = "post" action = "">
<?php $cycle = unserialize(BONUS_CYCLE_SELECT);
$cycle = array_reverse($cycle,true);
$payrollCycle = unserialize(PAYROLL_CYCLE_SELECT);
$stf = new Model_Payroll_Staffbonus();
$stDetail = new Model_DbTable_Roster_Stafflogindetail();
$stInfo = new Model_DbTable_Roster_Staffinfo();
$btype = new Model_Payroll_Staffbonustype();?>
<h2>Team Bonus All Summary</h2>
<?php echo "<img src='/im/yes20.jpg' />"."All Done					";  echo "<img src='/im/btn_edit_error.png' />"."Did But Not Finish	(Left People)		"; echo "<img src='/im/no20.jpg' />"."Have Not Start";?>
<br/>
<?php foreach($cycle as $cK => $cVal){
if($cK >= 5){?>
<br/>		
 
	<?php	$stfDetail = array();
			$stfDetail = $stf->listPeriodBonus($cVal[0],$cVal[1]);?>
<div <?php if(empty($stfDetail)){ ?> style = "display:none;" <?php }?>>		
<h3><a href = "javascript:toggle('dT<?=$cK?>');">Cycle <?php if($cK > 12){echo "2015-".($cK-12);}else{echo "2014-".$cK;}?> ( <?php echo $cVal[0];?> ~ <?php echo $cVal[1];?> )</a></h3>
</div>	
<?php 		
			
			if(!empty($stfDetail)){
			$total = count($stfDetail);
			$countCal = 0;
			$countPM = 0;
			$countDis = 0;
			$countPay = 0;
			foreach($stfDetail as $kStaff => $vStaff){
			
				if($vStaff['calculate_status'] == 'yes'){
					$countCal ++;
				}
				if($vStaff['pay_method_status'] == 'yes'){
					$countPM ++;
				}
				if($vStaff['display_status'] == 'yes'){
					$countDis ++;
				}
				if($vStaff['payment_status'] == 'yes'){
					$countPay ++;
				}
				?>
<?php 		} ?>
		<table border="0" cellspacing="1" cellpadding="5">
			<tr>
				<th>Calculation Status</th>
				<th><?php if($countCal == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countCal < $total && $countCal > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countCal).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Confirm Payment</th>
				<th><?php if($countPM == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countPM < $total && $countPM > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countPM).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Display to Staff</th>
				<th><?php if($countDis == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countDis < $total && $countDis > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countDis).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Pay to Staff</th>
				<th><?php if($countPay == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countPay < $total && $countPay > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countPay).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
			</tr>
		</table>	
		
		<div id = "dT<?=$cK?>" style="display:none;">
		<h3>Have not confirm paymethod/date release staff list<br/><br/>
		Cash List</h3>
		
		<table border="1" cellspacing="0" cellpadding="5" style="font-size:13px;">
			<tr>
				<td colspan = "4">&nbsp;</td>
				<td><input type = "submit" id = "saveChange[<?php echo $cK?>]" name = "saveChange[<?php echo $cK?>]" value = "Save Change"></input></td>
				<td colspan = "2">Tick<input type = "checkbox" id = "tickAll1_<?php echo $cK?>" onclick = "tickAll(this)"></input><input type = "text" class = "pick_date" onchange = "changeDate(this)" size = "15"></input></td>
				<td colspan = "2"><input type = "checkbox" id = "tickAll2_<?php echo $cK?>" onclick = "tickAll(this)"></input><select id="choose_cycle" onchange = "changeCycle(this)">
			<option selected="selected"  value = "" disabled>Please Select cycle</option>
				<?php foreach($payrollCycle as $k => $v){
					$cTotal = 0;
					$bTotal = 0;
					$btaxTotal = 0;
					$bsupTotal = 0;
					
					if($k > 26){?>
					<option value = "<?php echo $k;?>" ><?php if($k < 27){ echo $k;}else{echo ($k-26);}?>( <?php echo $v[0];?> ~ <?php echo $v[1];?> ) </option>
				<?php }}?>
		</select></td>
				<td colspan = "2">Tick All<input type = "checkbox" id = "tickAll3_<?php echo $cK?>"onclick = "tickAll(this)"></input></td>
				<td colspan = "2">&nbsp;</td>
				<td colspan = "2">Add Comment<input type = "text" name = "comment[<?php echo $cK?>]"></input></td>
			</tr>
			<tr>
    			<td width="65" style="width:65px;">ID Bonus</td>
    			<td width="120" style="width:120px;">Staff</td>
    			<td width="150" style="width:150px;">Bonus Type</td>
    			<td width="100" style="width:100px;">Total Amt</td>
    			<td width="140" style="width:180px;">Period</td>
    			<td colspan="2" style="width:100px;">Display date to Staff</td>
    			<td colspan="2" style="width:100px;">Pay with Payroll Cycle</td>
    			<td colspan="2" style="width:100px;">Finalized with Payroll Cycle</td>
    			<td width="45">Cancel</td>
   				<td width="180">Cancel Reason</td>
    			<td width="150" colspan = "2">Comment</td>
  			</tr>
		    <?php foreach ($stfDetail as $k2 => $v2){
		    	$btypeRow = $btype->getStaffbonustype($v2['type_bonus']);
		    	$sdRow = $stDetail->getDetail($v2['id_staff']);
		    	if($v2['calculate_status'] != 'yes' || $v2['pay_method_status'] != 'yes' || $v2['display_status'] != 'yes'){
		    	$nName = $sdRow['ni'];
		    	$fName = Model_EncryptHelper::getSslPassword($sdRow['n']);
		    		if($v2['cancel_status'] != 'yes'){
		    		  if($v2['pay_type'] == 1){
		    		  $leave = $stInfo->getStaffinfo($v2['id_staff']);
		    		  foreach($payrollCycle as $k => $v){
		    		  		if($v2['pay_date'] >= $v[0] && $v2['pay_date'] <= $v[1]){
		    		  			$payrollKey = $k;
		    		  		}
					  }?>
		    			<tr>
							<td><?php echo $v2['id_bonus'];?></td>
							<td><?php echo ucwords($nName." <br />[ ".$fName." ]");?></td>
							<td><?php echo $btypeRow['type_bonus']?></td>
							<td>$ <?php echo $v2['amt_total_bonus']?><?php $cTotal += $v2['amt_total_bonus']?></td>
							<td><?php echo $v2['period_bonus_begin']." to ".$v2['Period_bonus_end'];?></td>
							<td width="20"><input type="checkbox" name="check_release[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="check_release<?php echo $v2['id_bonus']?>" value="<?php echo $v2['id_bonus']?>" class = "check_release_<?php echo $cK?>"/></td>
    						<td width="60"><input type="text" name="date_release[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="date_release<?php echo $v2['id_bonus']?>" value="<?php echo $v2['display_date'];?>"  class = "date"/></td>
    						
							<td width="20"><input type="checkbox" name="check_delay[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="check_delay_<?php echo $cK?>" value="<?php echo $v2['id_bonus']?>" class = "check_delay_<?php echo $cK?>" /></td>
    						<td width="60"><select id="date_delay<?php echo $v2['id_bonus']?>" name = "date_delay[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" class = "choose_cycle">
								<option selected="selected"  value = "" disabled>Please Select</option>
								<?php foreach($payrollCycle as $k => $v){?>
								<option value = "<?php echo $k;?>" <?php echo ($payrollKey == $k)?'selected="selected"':''; ?>><?php if($k < 27){ echo $k;}else{echo ($k-26);}?>( <?php echo $v[0];?> ~ <?php echo $v[1];?> ) </option>
								<?php }?>
							</select></td>
    						
    						
    						
    						<td width="20"><input type="checkbox" name="pay_date_check[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="pay_date_check_<?php echo $cK?>" value="<?php echo $v2['id_bonus']?>" class = "pay_date_check_<?php echo $cK?>" /></td>
    						<td width="60">
    						<select id="pay_date<?php echo $v2['id_bonus']?>" name="pay_date[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]">
								<option selected="selected"  value = "" disabled>Please Select</option>
								<?php foreach($payrollCycle as $k => $v){?>
								<option value = "<?php echo $k;?>" <?php echo ($payrollKey == $k)?'selected="selected"':''; ?>><?php if($k < 27){ echo $k;}else{echo ($k-26);}?>( <?php echo $v[0];?> ~ <?php echo $v[1];?> ) </option>
								<?php }?>
							</select></td>
    						<td>
    						<input type="checkbox" name="check_cancel[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id ="check_cancel<?php echo $v2['id_bonus']?>" value= "1" />
    						</td>
    						<td <?php if($leave['leave'] == 9){if($leave['leave_date'] >= $v2['pay_date']){?>style = "background:green"<?php }}?>><input name="cancel_reason[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="cancel_reason[<?php echo $v2['id_bonus']?>]" type="text" style="width: 210px" 
    						 value = "<?php if($leave['leave'] == 9){ echo 'Leave on '.$leave['leave_date'];}else{echo $v2['hold_reason'];}?>"
    						/></td>
    						<td><?php echo $v2['detail_bonus']?></td>
    						<td><input type="checkbox" name="add_comment[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id ="add_comment<?php echo $v2['id_bonus']?>" /></td>
							</tr>
		    		<?php }?>
		    	<?php }?>
		    <?php }?>
		  <?php }?>
		  <tr>
		  		<td colspan = "15"><?php echo "Total:".$cTotal?></td>
		  		</tr>
		</table> 
		<h3>Bank List</h3>
		<table border="1" cellspacing="0" cellpadding="5" style="font-size:13px;">
   			 <tr>
    			<td width="65" style="width:65px;">ID Bonus</td>
    			<td width="120" style="width:120px;">Staff</td>
    			<td width="150" style="width:150px;">Bonus Type</td>
    			<td width="100" style="width:100px;">Total Amt</td>
    			<td width="100" style="width:100px;">Pay Bank</td>
    			<td width="100" style="width:100px;">Super</td>
    			<td width="180" style="width:180px;">Period</td>
    			<td colspan="2" style="width:100px;">Display date to Staff</td>
    			<td colspan="2" style="width:100px;">Pay with Payroll Cycle</td>
    			<td colspan="2" style="width:100px;">Finalized with Payroll Cycle</td>
    			<td width="50" style="width:50px;">Cancel</td>
    			<td width="200" style="width:170px;">Cancel Reason</td>
    			<td width="180" style="width:200px;">Comment</td>
  			</tr>
			<?php foreach($stfDetail as $k2 => $v2){
				$btypeRow = $btype->getStaffbonustype($v2['type_bonus']);
				$sdRow = $stDetail->getDetail($v2['id_staff']);
				$nName = $sdRow['ni'];
				$fName = Model_EncryptHelper::getSslPassword($sdRow['n']);
				if($v2['calculate_status'] != 'yes' || $v2['pay_method_status'] != 'yes' || $v2['display_status'] != 'yes'){
				if($v2['cancel_status'] != 'yes'){
				
					if($v2['pay_type'] == 2){
					  $leave = $stInfo->getStaffinfo($v2['id_staff']);
					  foreach($payrollCycle as $k => $v){
		    		  		if($v2['pay_date'] >= $v[0] && $v2['pay_date'] <= $v[1]){
		    		  			$payrollKey = $k;
		    		  		}
					  }?>
						<tr>
							<td><?php echo $v2['id_bonus'];?></td>
							<td><?php echo ucwords($nName." <br />[ ".$fName." ]");?></td>
							<td><?php echo $btypeRow['type_bonus']?></td>
							<td align="left">$ <?php echo $v2['amt_total_bonus']?><?php $bTotal += $v2['amt_total_bonus']?></td>
							<td align="left">$ <?php echo $v2['amt_bank_bonus']?><?php $btaxTotal += $v2['amt_bank_bonus']?></td>
    						<td align="left">$ <?php echo $v2['amt_bonus_super']?><?php $bsupTotal += $v2['amt_bonus_super']?></td>
    						<td><?php echo $v2['period_bonus_begin']." to ".$v2['Period_bonus_end'];?></td>
    						<td width="20"><input type="checkbox" name="check_release[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="check_release<?php echo $v2['id_bonus']?>" value="<?php echo $v2['id_bonus']?>" class = "check_release_<?php echo $cK?>"/></td>
    						<td width="144" <?php if($v2['display_status'] == 'yes'){ ?> style="background-color:#C90" <?php }?>><input type="text" name="date_release[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="date_release<?php echo $v2['id_bonus']?>" value="<?php echo $v2['display_date'];?>"  class = "date"/></td>
    						<td width="20"><input type="checkbox" name="check_delay[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="check_delay_<?php echo $cK?>" value="<?php echo $v2['id_bonus']?>" class = "check_delay_<?php echo $cK?>" /></td>
    						<td width="60"><select id="date_delay<?php echo $v2['id_bonus']?>" name = "date_delay[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" class = "choose_cycle">
								<option selected="selected"  value = "" disabled>Please Select</option>
								<?php foreach($payrollCycle as $k => $v){?>
								<option value = "<?php echo $k;?>" <?php echo ($payrollKey == $k)?'selected="selected"':''; ?>><?php if($k < 27){ echo $k;}else{echo ($k-26);}?>( <?php echo $v[0];?> ~ <?php echo $v[1];?> ) </option>
								<?php }?>
							</select></td>
    						
    						
    						
    						<td width="20"><input type="checkbox" name="pay_date_check[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="pay_date_check_<?php echo $cK?>" value="<?php echo $v2['id_bonus']?>" class = "pay_date_check_<?php echo $cK?>" /></td>
    						<td width="60">
    						<select id="pay_date<?php echo $v2['id_bonus']?>" name="pay_date[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]">
								<option selected="selected"  value = "" disabled>Please Select</option>
								<?php foreach($payrollCycle as $k => $v){?>
								<option value = "<?php echo $k;?>" <?php echo ($payrollKey == $k)?'selected="selected"':''; ?>><?php if($k < 27){ echo $k;}else{echo ($k-26);}?>( <?php echo $v[0];?> ~ <?php echo $v[1];?> ) </option>
								<?php }?>
							</select></td>
    						<td>
    						<input type="checkbox" name="check_cancel[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id ="check_cancel<?php echo $v2['id_bonus']?>" value= "2" />
   							</td>
    						<td <?php if($leave['leave'] == 9){if($leave['leave_date'] >= $v2['pay_date']){?>style = "background:green"<?php }}?>><input name="cancel_reason[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id="cancel_reason[<?php echo $v2['id_bonus']?>]" type="text" style = "width:180px" value = "<?php if($leave['leave'] == 9){ echo 'Leave on '.$leave['leave_date'];}else{ echo $v2['hold_reason'];}?>"/></td>
    						<td><?php echo $v2['detail_bonus']?></td>
    						<td><input type="checkbox" name="add_comment[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" id ="add_comment<?php echo $v2['id_bonus']?>" /></td>
  						</tr>
		
					<?php }?>
				<?php }?>	
			<?php }?>		
		<?php }?>	
			<tr>
				<td colspan ="3">&nbsp;</td>
		  		<td><?php echo "Total:".$bTotal?></td>
		  		<td><?php echo $btaxTotal?></td>
		  		<td><?php echo $bsupTotal?></td>
		  	</tr>
			</table> 
			</div>
			<?php }else{?>
			<div style = "display:none;">
				<table border="0" cellspacing="1" cellpadding="5">
					<tr>
						<th>Calculation Status</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Confirm Payment</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Display to Staff</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Pay to Staff</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
					</tr>
				</table>
			</div>	
			<?php }?>
	<?php }?>			
<?php }?> 
</form>

<input type = "submit" name = "close" id = "close" value = "Finish" onclick = "closeWin()"></input>
</body>
</html>
